package mars.activity;


import java.util.ArrayList;
import java.util.HashMap;

import bear.download.HttpsUtils;
import bear.download.Msgread;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class receiveActivity extends ListActivity{
	public static int idt=0;
	private Button turnup6,turndown6;
	private TextView pages6;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.receive);
		pages6=(TextView)findViewById(R.id.pages6);
        turnup6=(Button)findViewById(R.id.turnup6);
        turndown6=(Button)findViewById(R.id.turndown6);
        pages6.setText("1/1");
        turndown6.setOnClickListener(new Button.OnClickListener()
        {
			public void onClick(View v) {
				// TODO Auto-generated method stub;
				Toast.makeText(receiveActivity.this, R.string.down0,Toast.LENGTH_LONG).show();
			}	
        });
        turnup6.setOnClickListener(new Button.OnClickListener()
        {
			public void onClick(View v) {
				// TODO Auto-generated method stub;
				Toast.makeText(receiveActivity.this, R.string.up0,Toast.LENGTH_LONG).show();
			}	
        });
		
		String senders[] = Msgread.sender1.split("\\$");
		String times[]=Msgread.time1.split("\\$");
		String reads[]=Msgread.read1.split("\\$");
		String readed[]=reads;
		for(int j=0;j<Msgread.n;j++){
			for(int t=0;t<Msgread.n;t++){
				if(reads[j].equals("0")){
					readed[t]=getString(R.string.readtt);
				}else if(reads[j].equals("1")){
					readed[t]=getString(R.string.readed);
				}
			}
		}
		
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for(int i=0;i<Msgread.n;i++){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("perple", senders[i]);
		map.put("timepd", times[i]);
		map.put("read", readed[i]);
		list.add(map);
		}
		SimpleAdapter listAdapter = new SimpleAdapter(receiveActivity.this, list,
				R.layout.mesrec, new String[] { "perple", "timepd","read"},
				new int[] { R.id.perple,R.id.timepd,R.id.read});
		setListAdapter(listAdapter);
	}
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		idt=position;
		String ids[]=Msgread.mesid1.split("\\$");
		HttpsUtils readt=new HttpsUtils();
		String real=readt.get("http://www.loushiapp.com/?c=pm&a=readpm&hash="+landActivity.hash+"&id="+ids[position]);
		System.out.println(real);
				Intent intentapp=new Intent();
		intentapp.setClass(receiveActivity.this, applicatActivity.class);
		receiveActivity.this.startActivity(intentapp);
		
			}
}
